package com.yeskery.nut.extend.mcp;

import com.yeskery.nut.bean.BeanPostProcessor;
import com.yeskery.nut.extend.mcp.server.*;
import com.yeskery.nut.plugin.ApplicationContextSupportBasePlugin;
import com.yeskery.nut.plugin.PluginBeanMetadata;
import com.yeskery.nut.plugin.ServerEventPlugin;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 基础MCP Server插件
 * @author sprout
 * 2025-04-17 10:25
 */
public abstract class BaseMcpServerPlugin extends ApplicationContextSupportBasePlugin implements ServerEventPlugin {

    /** 会话SSE会话管理器 */
    private final McpSessionManager mcpSessionManager = new McpSessionManager();

    /** MCP服务能力 */
    private final McpServerCapability mcpServerCapability = new McpServerCapability();

    @Override
    public Collection<PluginBeanMetadata> getRegisterPluginBeanMetadata() {
        List<PluginBeanMetadata> pluginBeanMetadataList = new ArrayList<>();
        pluginBeanMetadataList.add(new PluginBeanMetadata("mcpSessionManager", mcpSessionManager, McpSessionManager.class));
        pluginBeanMetadataList.add(new PluginBeanMetadata("mcpServerCapability", mcpServerCapability, McpServerCapability.class));
        pluginBeanMetadataList.add(new PluginBeanMetadata("mcpToolBeanPostProcessor", new McpToolBeanPostProcessor(mcpServerCapability),
                McpToolBeanPostProcessor.class, BeanPostProcessor.class));
        pluginBeanMetadataList.add(new PluginBeanMetadata("mcpResourceBeanPostProcessor", new McpResourceBeanPostProcessor(mcpServerCapability),
                McpResourceBeanPostProcessor.class, BeanPostProcessor.class));
        pluginBeanMetadataList.add(new PluginBeanMetadata("mcpPromptBeanPostProcessor", new McpPromptBeanPostProcessor(mcpServerCapability),
                McpPromptBeanPostProcessor.class, BeanPostProcessor.class));
        return pluginBeanMetadataList;
    }

    /**
     * 获取MCP会话管理器
     * @return 会话管理器
     */
    public McpSessionManager getMcpSessionManager() {
        return mcpSessionManager;
    }

    /**
     * 获取MCP服务能力
     * @return MCP服务能力
     */
    public McpServerCapability getMcpServerCapability() {
        return mcpServerCapability;
    }
}
